using System;
using System.Collections;
using System.Web.UI;
using System.Web.UI.WebControls;
using App_Code.Modules;
using Portal.Data.Entity;
using Portal.Core;

public partial class Modules_Banner_List : BannerModule
{
    protected override string Action
    {
        get
        {
            return "lists";
        }
    }
    private const int PageSize = 10;

    protected override void OnLoad(EventArgs e)
    {
        if (!IsPostBack)
        {
            int count = 0;
            IList list = Banner.Paging(PageSize, GetCurrentPage(), out count);

            Contents.DataSource = list;
            Contents.DataBind();

            AddPagingTool(new Control[] { phPagingBottom, phPagingTop }, count, PageSize, null);
        }
    }

    protected void Contents_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        int ID = Convert.ToInt32(e.CommandArgument);
        if (e.CommandName == "Delete")
        {
            (Banner.FindByPrimaryKey(ID)).Delete();
            Forward("delete");
        }
        else if (e.CommandName == "Edit")
        {
            ActionPage.newParams.Add("id", ID);
            Forward("edit");
        }
    }

    protected string BuildPositions(object eval)
    {
        var list = BannerGroup.FindByBanner(Convert.ToInt32(eval));
        var result = "";
        if (list.Count > 0)
        {
            result = @"<br/><div style='font-style:italic'>(";
            foreach (BannerGroup bg in list)
            {
                result += string.Format("{0},", ObjectBannerPositionClass.GetName(bg.GroupID));
            }
            if (result.Length > 0)
                result = result.Substring(0, result.Length - 1);
            result += ")</div>";
        }
        return result;

    }
}